﻿var current_user = "px";
var current_projectId = 1;// 默认项目总是为1，default

Ext.define('app.prm.task.Task', {
    extend: 'Ext.Panel',
    border: false,
    layout: 'border',
    treeView: false,// 树形视图
    initComponent: function () {
        var me = this;
        me.items = [this.getTasksPanel(), this.getFilterPanel()];
        me.callParent();
    },
    getTasksPanel: function () //任务列表
    {
        if (!this.tasksPanel) {
            this.tasksPanel = new Ext.Panel(
            {
                margins: '5',
                region: 'center',
                tbar: [
                    "<b>任务中心</b>",
                    '->',
                ],
                layout: 'border',
                items: [
                    {
                        xtype: 'panel',
                        region: 'north',
                        height: 40,
                        bodyStyle: 'border-width:0 0 1px 0;',
                        layout: 'border',
                        items: [
                            this.getActionBar(),
                            this.getTipsPanel()
                        ]
                    },

                    this.getCardPanel()
                ]
            });
        }
        return this.tasksPanel;
    },
    getFilterPanel: function () {
        if (!this.filterPanel) {
            this.filterPanel = new Ext.Panel(
                {
                    margins: '5 5 5 0',
                    region: 'east',
                    //split: true,
                    width: 300,
                    tbar: [
                        "<b>任务筛选</b>",
                        '->',
                        {
                            text: '清除筛选',
                            scope: this,
                            handler: function () {
                                console.log('清除筛选');
                                this.clearFilter();
                            }
                        }
                    ],
                    layout: 'fit',
                    defaults: {
                        border: false,
                        frame: false
                    },
                    items: [this.getFilterForm()]
                });
        }
        return this.filterPanel;
    },

    getFilterForm: function () {
        if (!this.formPanel) {
            this.formPanel = new Ext.Panel(
            {
                labelWidth: 10,
                labelAlign: 'left',
                defaultType: 'textfield',
                layout: {
                    type: 'table',
                    // The total column count must be specified here
                    columns: 2
                },
                bodyStyle: 'padding:20px',
                items: [
                    {
                        xtype: 'checkbox',
                        boxLabel: '我关注的',//=================
                        inputValue: 'follow',
                        name: 'people'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '有项目的',//******************
                        inputValue: 'has',
                        name: 'hasProject'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '我创建的',//=================
                        inputValue: 'create',
                        name: 'people'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '显示未开始',//staus staus staus staus staus staus staus staus staus staus staus staus 
                        inputValue: '未开始',
                        name: 'status'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '我负责的',//=================
                        inputValue: 'manaer',
                        name: 'people'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '显示进行中',//staus staus staus staus staus staus staus staus staus staus staus staus 
                        inputValue: '进行中',
                        name: 'status'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '我指派的',//=================
                        inputValue: 'assigned',
                        name: 'people'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '显示已暂停',//staus staus staus staus staus staus staus staus staus staus staus staus 
                        inputValue: '已暂停',
                        name: 'status'

                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '我参与的',//=================
                        inputValue: 'participate',
                        name: 'people'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '显示已完成',//staus staus staus staus staus staus staus staus staus staus staus staus 
                        inputValue: '已完成',
                        name: 'status'

                    },
                    {
                        style: 'margin-top:10px;',
                        width: '80%',
                        emptyText: '输入任务名称筛选',
                        name: 'taskName',
                        selectOnFocus: true,
                        colspan: 2
                    },
                    {
                        width: '80%',
                        emptyText: '输入项目名称筛选',
                        name: 'projectName',
                        hidden: current_projectId > 1,
                        selectOnFocus: true,
                        colspan: 2
                    },
                    {
                        width: '80%',
                        emptyText: '输入标签筛选',
                        name: 'tag',
                        selectOnFocus: true,
                        colspan: 2
                    },
                    {
                        style: 'margin-top:5px;',
                        xtype: 'displayfield',
                        value: '<b>按旗帜筛选</b>',
                        colspan: 2
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '<span class="i_Flag_red">red</span>',
                        inputValue: 'red',
                        name: 'flag'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '<span class="i_Flag_purple">purple</span>',
                        inputValue: 'purple',
                        name: 'flag'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '<span class="i_Flag_green">green</span>',
                        inputValue: 'green',
                        name: 'flag'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '<span class="i_Flag_pink">pink</span>',
                        inputValue: 'pink',
                        name: 'flag'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '<span class="i_Flag_yellow">yellow</span>',
                        inputValue: 'yellow',
                        name: 'flag'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '<span class="i_Flag_orange">orange</span>',
                        inputValue: 'orange',
                        name: 'flag'
                    },

                    {
                        xtype: 'checkbox',
                        boxLabel: '<span class="i_Flag_blue">blue</span>',
                        inputValue: 'blue',
                        colspan: 2,
                        name: 'flag'
                    },
                    {
                        style: 'margin-top:5px;',
                        xtype: 'displayfield',
                        value: '<b>按截止日期筛选</b>',
                        colspan: 2
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '今天',
                        inputValue: '今天',
                        name: 'dtime'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '明天',
                        inputValue: '明天',
                        name: 'dtime'
                    },

                    {
                        xtype: 'checkbox',
                        boxLabel: '本周',
                        inputValue: '本周',
                        name: 'dtime'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '下周',
                        inputValue: '下周',
                        name: 'dtime'
                    },

                    {
                        xtype: 'checkbox',
                        boxLabel: '本月',
                        inputValue: '本月',
                        name: 'dtime'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '下月',
                        inputValue: '下月',
                        name: 'dtime'
                    },

                    {
                        xtype: 'checkbox',
                        boxLabel: '已过期',
                        inputValue: '已过期',
                        name: 'dtime'
                    },
                    {
                        xtype: 'checkbox',
                        boxLabel: '无期限',
                        inputValue: '无期限',
                        name: 'dtime'
                    },
                    {
                        style: 'margin:10px 0 5px 0;',
                        xtype: 'displayfield',
                        value: '<b>按成员筛选</b>',
                        colspan: 2
                    },
                    {
                        name: '创建人',
                        width: '80%',
                        colspan: 2,
                        selectOnFocus: true,
                        emptyText: '输入创建人姓名筛选'
                    },
                    {
                        name: '负责人',
                        width: '80%',
                        emptyText: '输入负责人姓名筛选',
                        selectOnFocus: true,
                        colspan: 2
                    },
                    {
                        name: '参与者',
                        width: '80%',
                        emptyText: '输入参与者姓名筛选',
                        selectOnFocus: true,
                        colspan: 2,
                        enableKeyEvents: true,
                        listeners: {}
                    }


                ]
            });


            var task = new Ext.util.DelayedTask();
            var runFilter = function (_args) {
                console.log(_args);
                this._refreshStore();
            };


            // 绑这 change 事件 
            var _textfields = this.formPanel.down('textfield', false);
            for (var i = 0; i < _textfields.length; i++) {
                _textfields[i].enableKeyEvents = true;
                _textfields[i].on('keyup', function (sender, e) {
                    task.delay(500, runFilter, this, [sender.name + '.' + 'keyup' + ': ' + sender.getRawValue()]);
                }, this);
                _textfields[i].on('change', function (sender, e) {
                    task.delay(500, runFilter, this, [sender.name + '.' + 'change' + ': ' + sender.getRawValue()]);
                }, this);
            }

            var _checkboxs = this.formPanel.down('checkbox', false);
            for (var i = 0; i < _checkboxs.length; i++) {
                _checkboxs[i].on('check', function (sender, checked) {
                    task.delay(500, runFilter, this, [sender.name + '.' + 'check' + ': ' + sender.getRawValue() + ': ' + checked]);
                }, this);
            }
        }
        return this.formPanel;
    },

    _refreshStore: function () {
        var date1 = new Date();

        var form = this.getFilterForm().getForm();
        var formValues = form.getValues();
        for (var param in formValues) {
            if (form.findField(param) && form.findField(param).emptyText == formValues[param]) {
                formValues[param] = undefined;
            }
        }


        // 重复的检索条件，不再执行。。可以使用该值为key，建立key-value队，将结果集存储起来，当以后还有同样的检索时，就不用再检索了。
        var newQueryStr = Ext.encode(formValues);
        console.log("formValues： " + newQueryStr);
        if (this.prevQueryStr && this.prevQueryStr == newQueryStr) {
            console.log("this.prevQueryStr == newQueryStr , return ! ");
            return;
        }
        this.prevQueryStr = newQueryStr;

        // 在objs中查找fname属性为val的对象
        var indexOf = function (objs, fname, val) {
            for (var i = 0; i < objs.length; i++) {
                if (objs[i][fname] == val) {
                    return i;
                }
            }
            return -1;
        };



        var filterByPeople = function (record) {

            // record.get("Title");

            var people = formValues["people"];
            if (people) {
                if (!Ext.isArray(people)) {
                    people = [people];
                }
            }
            //  follow", "create", "manaer", "assigned", "participate"
            if (people && people.length < 5) {// 一个都没选，或着是全选中，就不过滤了。
                var _b = false; //只要有一个选中，就是可以返回需要显示的。
                for (var i = 0; i < people.length; i++) {
                    switch (people[i]) {
                        case "follow":
                            var _fs = record.get('Follow');
                            if (indexOf(_fs, 'Name', current_user) > -1) {
                                _b = true;
                            }
                            break;
                        case "create":
                            if (record.get('CreateBy') == current_user) {
                                _b = true;
                            }
                            break;
                        case "manaer":
                            if (record.get('Manager') == current_user) {
                                _b = true;
                            }
                            break;
                        case "assigned":
                            var _fs = record.get('Assigned');
                            if (indexOf(_fs, 'Name', current_user) > -1) {
                                _b = true;
                            }
                            break;
                        case "participate":
                            var _fs = record.get('Participants');
                            if (indexOf(_fs, 'Name', current_user) > -1) {
                                _b = true;
                            }
                            break;
                    }
                }
                return _b;
            }


            return true;
        };
        var filterByHasProject = function (record) {

            // hasProject: "has"
            var haspro = formValues["hasProject"];
            if (haspro && haspro == 'has') {
                if (!record.get('Project') || record.get('Project').length < 1)
                    return false;
            }
            return true;
        };
        var filterByStatus = function (record) {

            // record.get("Title");

            var status = formValues["status"];
            if (status) {
                if (!Ext.isArray(status)) {
                    status = [status];
                }
            }
            // status:[ "未开始", "进行中", "已暂停", "已完成"]
            if (status && status.length < 4) {// 一个都没选，或着是全选中，就不过滤了。 

                var _s = record.get('State');

                //未开始 = 0,
                //进行中 = 1,
                //已暂停 = 2,
                //已完成 = 100,
                //已归档 = 200


                var _b = false; //只要有一个选中，就是可以返回需要显示的。
                for (var i = 0; i < status.length; i++) {
                    var _rv = -1;
                    switch (status[i]) {
                        case "未开始":
                            _rv = 0;
                            break;
                        case "进行中":
                            _rv = 1;
                            break;
                        case "已暂停":
                            _rv = 2;
                            break;
                        case "已完成":
                            _rv = 100;
                            break;
                    }
                    if (_s == _rv) {
                        _b = true;
                        break;
                    }
                }
                return _b;
            }


            return true;
        };
        var filterByTaskName = function (record) {
            var txt = formValues["taskName"];
            if (txt) {
                txt = txt.trim();
                if (txt.length > 0) {
                    var reCat = new RegExp(txt, "i");//   i:不区分大小写
                    var sToMatch = record.get('Title');
                    if (!reCat.test(sToMatch)) {
                        return false;
                    }
                }
            }
            return true;
        };
        var filterByProjectName = function (record) {
            //   projectName: "pname",
            var txt = formValues["projectName"];
            if (txt) {
                txt = txt.trim();
                if (txt.length > 0) {
                    var reCat = new RegExp(txt, "i");//   i:不区分大小写
                    var sToMatch = record.get('Project');
                    if (!reCat.test(sToMatch)) {
                        return false;
                    }
                }
            }

            return true;
        };
        var filterByTag = function (record) {
            var txt = formValues["tag"];
            if (txt) {
                txt = txt.trim();
                if (txt.length > 0) {
                    var reCat = new RegExp(txt, "i");//   i:不区分大小写

                    var _b = false;
                    var ps = record.get('Tags');
                    if (ps && ps.length > 0) {
                        for (var i = 0; i < ps.length; i++) {
                            var sToMatch = ps[i];
                            if (reCat.test(sToMatch)) {
                                _b = true;
                                break;
                            }
                        }//end for
                    }
                    return _b;
                }
            }

            return true;
        };
        var filterByFlags = function (record) {

            var flag = formValues["flag"];
            if (flag) {
                if (!Ext.isArray(flag)) {
                    flag = [flag];
                }
            }
            //  flag:[ "red", "purple", "green", "pink", "yellow", "orange", "blue"]
            if (flag && flag.length < 7) {//  一个都没选，或着是全选中，就不过滤了。 

                var _s = record.get('Flags');

                var _b = false; //只要有一个选中，就是可以返回需要显示的。
                for (var i = 0; i < flag.length; i++) {
                    if (_s.indexOf(flag[i]) > -1) {
                        _b = true;
                        break;
                    }
                }
                return _b;
            }
            return true;
        };
        var filterByDeliverydate = function (record) {
            var dtimes = formValues["dtime"];
            if (dtimes) {
                if (!Ext.isArray(dtimes)) {
                    dtimes = [dtimes];
                }
            }
            //"dtime":["今天","明天","本周","下周","本月","下月","已过期","无期限"]
            if (dtimes && dtimes.length < 8) {// 一个都没选，或着是全选中，就不过滤了。 


                var _basedate = new Date("2010/10/10");// 用来比较用的基准日期,最小的有效交期不会小于该值。
                var _tmpdt = record.get('Deliverydate') || "2010/10/9";// 若没有时间，则比交期小一天
                var _deliverydate = new Date(_tmpdt.replace(/-/g, "/"));
                var _nowdate = new Date(new Date().toLocaleDateString());

                //var _weekday = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"][_now.getDay()];
                var _weekday = _nowdate.getDay();  //  0~6 
                if (_weekday == 0) {
                    _weekday = 7; //  1~7
                }
                var _monthday = _nowdate.getDate();//几号。
                var _monthlastday = _nowdate.getDaysInMonth();// 该月的最后一天是几号


                var _b = false; //只要有一个选中，就是可以返回需要显示的。
                for (var i = 0; i < dtimes.length; i++) {
                    var _beg = undefined;
                    var _end = undefined;
                    switch (dtimes[i]) {
                        case "今天":
                            _beg = _nowdate;
                            _end = _nowdate;
                            break;
                        case "明天":
                            _beg = _nowdate.add(Date.DAY, 1);
                            _end = _nowdate.add(Date.DAY, 1);
                            break;
                        case "本周":
                            _beg = _nowdate.add(Date.DAY, -1 * (_weekday - 1));
                            _end = _nowdate.add(Date.DAY, 7 - _weekday);
                            break;
                        case "下周":
                            _beg = _nowdate.add(Date.DAY, 7 - _weekday + 1);
                            _end = _nowdate.add(Date.DAY, 7 - _weekday + 7);
                            break;
                        case "本月":
                            _beg = _nowdate.add(Date.DAY, -1 * (_monthday - 1));
                            _end = _nowdate.add(Date.DAY, _monthlastday - _monthday);
                            break;
                        case "下月":
                            var _nextmonthlastday = _nowdate.add(Date.MONTH, 1).getDaysInMonth();

                            _beg = _nowdate.add(Date.DAY, _monthlastday - _monthday + 1);
                            _end = _nowdate.add(Date.DAY, _monthlastday - _monthday + _nextmonthlastday);
                            break;
                        case "已过期":
                            _beg = _basedate;
                            _end = _nowdate.add(Date.DAY, -1);
                            break;
                        case "无期限":
                            _beg = _basedate.add(Date.DAY, -1);
                            _end = _basedate.add(Date.DAY, -1);
                            break;
                    }

                    //console.log('_beg: ' + _beg.format('Y-m-d') + ' ; _end: ' + _end.format('Y-m-d'));
                    if (_beg <= _deliverydate && _end >= _deliverydate) {
                        _b = true;
                        break;
                    }
                }
                return _b;
            }
            return true;
        };
        var filterByCreate = function (record) {
            var txt = formValues["创建人"];//   "创建人":"123"
            if (txt) {
                txt = txt.trim();
                if (txt.length > 0) {
                    var reCat = new RegExp(txt, "i");//   i:不区分大小写
                    var sToMatch = record.get('CreateBy');
                    if (!reCat.test(sToMatch)) {
                        return false;
                    }
                }
            }
            return true;
        };
        var filterByManager = function (record) {
            var txt = formValues["负责人"];//   "负责人":"输入负责人姓名筛选"
            if (txt) {
                txt = txt.trim();
                if (txt.length > 0) {
                    var reCat = new RegExp(txt, "i");//   i:不区分大小写
                    var sToMatch = record.get('Manager');
                    if (!reCat.test(sToMatch)) {
                        return false;
                    }
                }
            }
            return true;
        };
        var filterByParticipants = function (record) {
            var txt = formValues["参与者"];//  "参与者":"输入参与者姓名筛选"
            if (txt) {
                txt = txt.trim();
                if (txt.length > 0) {
                    var reCat = new RegExp(txt, "i");//   i:不区分大小写

                    var _b = false;
                    var ps = record.get('Participants');
                    if (ps && ps.length > 0) {
                        for (var i = 0; i < ps.length; i++) {
                            var sToMatch = ps[i].Name;
                            if (reCat.test(sToMatch)) {
                                _b = true;
                                break;
                            }
                        }//end for
                    }
                    return _b;
                }
            }
            return true;
        };
        var filter = function (record) {

            if (!filterByPeople(record)) return false;
            if (!filterByTaskName(record)) return false;
            if (!filterByProjectName(record)) return false;
            if (!filterByTag(record)) return false;
            if (!filterByHasProject(record)) return false;
            if (!filterByStatus(record)) return false;
            if (!filterByFlags(record)) return false;
            if (!filterByDeliverydate(record)) return false;
            if (!filterByCreate(record)) return false;
            if (!filterByManager(record)) return false;
            if (!filterByParticipants(record)) return false;

            return true;
        };

        this.getTaskStore().filterBy(filter);

        this.getTipsPanel().update('经过 ' + (new Date() - date1) + ' ms 的努力搜索,为您找到相关结果 <b>' + this.getTaskStore().getCount() + ' </b>个！')
    },

    clearFilter: function () {
        this.getFilterForm().form.reset();
        if (this.getTaskStore().isFiltered()) {
            this.getTaskStore().clearFilter();
        }
    },
    getTaskStore: function () {
        if (!this.taskStore) {
            this.taskStore = Ext.create("app.ux.PrmStore", { url: '/api/services/app/gantt/GetAllTasks' });

            this.taskStore.on('load', function (sender, records, options) {
                this.getTipsPanel().update('为您找到相关结果 <b>' + sender.getCount() + ' </b>个');
            }, this);
        }
        return this.taskStore;
    },


    setActionBar: function (dataview, selectionsArray) {

        if (dataview && dataview.getSelectionCount() > 0) {

            // 判断操作按钮是否已经加载过。
            if (!this.getActionBar().initBtns) {
                this.getActionBar().add([
                {
                    //hidden:true,
                    xtype: 'button',
                    ref: 'edit',  //   this.getActionBar().edit >> get button,取直接子级的元素,若是在bar里面定义的，则使用 ../edit 
                    text: "批量属性设置"
                },
                {
                    //hidden: true,
                    xtype: 'button',
                    ref: 'end',  //   this.getActionBar().edit >> get button 
                    text: "设置为已完成"
                }]);
                this.getActionBar().doLayout();
                console.log('加载操作按钮.... 完成');
                this.getActionBar().initBtns = true;
            }


            this.getActionBar().edit.show();
            this.getActionBar().end.show();
        }
        else {
            this.getActionBar().edit.hide();
            this.getActionBar().end.hide();
        }
    },

    getActionBar: function () {
        if (!this.actionPanel) {
            this.actionPanel = new Ext.Panel(
            {
                initBtns: false,
                layoutConfig: {
                    padding: '5',
                    align: 'stretch'
                },
                defaults: { margins: '0 5 0 0' },
                border: false,
                frame: false,
                region: 'center',
                layout: 'hbox'
            });
            return this.actionPanel;
        };
    },
    getTipsPanel: function () {
        if (!this.tipsPanel) {
            this.tipsPanel = new Ext.Panel(
            {
                border: false,
                frame: false,
                region: 'east',
                bodyStyle: 'text-align:right;line-height:40px; padding-right:20px;color: #999;font-size: 12px ',
                width: 300,
                html: "loading...",
                items: []
            });
        }
        return this.tipsPanel;
    },
    getCardPanel: function () {
        if (!this.cardPanel) {
            this.cardPanel = new Ext.Panel(
            {
                border: false,
                frame: false,
                autoScroll: true,
                region: 'center',
                layout: "card",
                items: [this.getTile(), this.getTree()],
                activeItem: 0
            });
        }
        return this.cardPanel;
    },

    // 平铺视图  >>  DataView
    getTile: function () {
        if (!this.dataview) {
            this.dataview = new Ext.view.View({
                store: this.getTaskStore(),
                tpl: this.getDatatpl(),
                autoHeight: true,
                multiSelect: true,// 能不能选中。选中多个，批量操作。
                overClass: 'x-view-over',
                itemSelector: 'table.tb_taskitem',// tpl 里面可以选中的容器样式。
                emptyText: 'No data to display',
                listeners: {
                    click: function (view, index, node, event) {
                        //console.log('dataView.click(%o,%o,%o,%o)', view, index, node, event);
                    },
                    itemdblclick: function (view, record, item, index, e, eOpts) {
                        //console.log('dataView.dblclick(%o,%o,%o,%o)', view, index, node, event);
                        var taskId = record.data.id;

                        var task = Ext.create('app.prm.task.edit.Edit', { taskId: taskId });
                        task.show();
                    },
                    selectionchange: {
                        scope: this,
                        fn: function (view, selectionsArray) {
                            //console.log('dataView.selectionchange(%o,%o)', view, selectionsArray);
                            //console.log('getSelectionCount: ' + view.getSelectionCount());
                            //console.log('getSelectedIndexes: ' + view.getSelectedIndexes());
                            //console.log('selectionsArray: ' + selectionsArray.length);

                            //var _records = view.getSelectedRecords();
                            //_records[0].data.Id
                            //this.setActionBar(view, selectionsArray);
                        }
                    }
                }
            });
        }
        return this.dataview;
    },
    getDatatpl: function () {
        return new Ext.XTemplate(
        '<div class="div_taskviews">',
        '<tpl for=".">',
        '<table border="0"  cellpadding="0" id="{id}"  class="tb_taskitem">',
            '<tr>',
                '<td rowspan="3" class="td_Check">',
                    '<input type="checkbox" value="{id}" />',
                '</td>',
                '<td>',
                        '<tpl if="this.hasStar(follow)"><i class="i_Star"></i></tpl>',
                '</td>',
                '<td colspan="5">{[this.parseFlags(values.Flags)]}</i></td>',
                '<td>{Project}</td>',
            '</tr>',
            '<tr>',
                '<td colspan="7" class="td_Title">{title}  {createBy}</td>',
        ' </tr>',
            '<tr>',
                '<td width="120px">{[this.format_Deliverydate(values.deliverydate)]}</td>',
                '<td>{[this.format_Subtasks(values.subtasks)]}</td>',
                '<td>{[this.format_Attachment(values.attachment)]}</td>',
                '<td>{[this.format_Comments(values.comments)]}</td>',
                '<td>{[this.format_Describe(values.describe)]}</td>',
                '<td width="150px">{[this.format_Manager(values.Manager)]}</td>',
                '<td>{[this.format_Participants(values)]}</td>',
            '</tr>',
            '<tr>',
                '<td colspan="8" title="进度：{progress}%，{progress:this.parseCompletion()}完成日期：{completiondate}">',
                    '<div style="width:{[values.progress >100 ? "100" :values.progress]}%;" class="dv_ProgressBar"></div> ',
                '</td>',
            '</tr>',
        '</table>',
        '</tpl>',
        '</div>', {
            parseFlags: function (v) {
                var res = '';
                if (v && v.length > 0 && Ext.isArray(v)) {
                    Ext.each(v, function (item) {
                        res += '<i class="i_Flag_' + item + '"></i>';
                    });
                }
                return res;
            },
            //parseProgress: function (v) {
            //    if (v > 100) {
            //        return 100;
            //    }
            //    return v;
            //},
            parseCompletion: function (v) {
                if (v < 100) {
                    return '预期';
                }
                return '';
            },
            hasStar: function (v) {
                return v == true;
            },

            format_Deliverydate: function (v) {
                if (v && v.length > 0) {
                    console.log(v);
                    return '<span class="i_Deliverydate" title="截止日期：' + v + '">' + v.split(" ")[0] + '</span>';
                }
            },
            format_Attachment: function (v) {
                if (v && v.length > 0 && Ext.isArray(v)) {
                    v = v.length;
                    return '<span class="i_Attachment" title="有' + v + '个附件">' + v + '</span>';
                }
            },
            format_Comments: function (v) {
                if (v && v.length > 0 && Ext.isArray(v)) {
                    v = v.length;
                    return '<span class="i_Comments" title="有' + v + '个评论">' + v + '</span>';
                }
            },
            format_Describe: function (v) {
                if (v && v.length > 0) {
                    return '<span class="i_Describe"  title="有更多描述，点击任务详细查看"></span>';
                }
            },
            format_Manager: function (v) {
                if (v && v.length > 0) {
                    return '<span class="i_Manager" title="负责人：' + v + '">' + v + '</span>';
                }
            },
            format_Participants: function (v) {
                var parts = v.Participants;
                if (parts && parts.length > 0 && Ext.isArray(parts)) {
                    var ps = [];
                    Ext.each(parts, function (item) {
                        ps.push(item.Name);
                    });
                    ps = ps.join(',');
                    return '<span class="i_Participants" title="参与者：' + ps + '">' + ps + '</span>'
                }
                return '';
            },
            format_Subtasks: function (v) {
                if (v && v.length > 0 && Ext.isArray(v)) {
                    var ok = 0;
                    var all = v.length;
                    Ext.each(v, function (sub) {
                        switch (sub.State) {
                            case 0:
                                break;
                            case 1:
                                break;
                            case 2:
                                break;
                            case 100:
                            case 200:
                                ok++;
                                break;
                        }

                    });

                    return '<span  title="共有' + all + '个子任务，已完成' + ok + '个" class="i_Subtasks">' + ok + ' / ' + all + '</span>'
                }
                return '';
            }

        }
                    );
    },


    // 树形视图
    getTree: function () {
        if (!this.tree) {
            this.tree = new Ext.Panel(
            {
                border: false,
                frame: false,
                html: "___*树形视图*___*___"
            });
        }
        return this.tree;
    },





    get_____Panel: function () {
        if (!this._____Panel) {
            this._____Panel = new Ext.Panel(
            {
                html: "___*___*___*___"
            });
        }
        return this._____Panel;
    },
    _end: undefined
});